package net.orange.console.genius;

import java.util.Collection;

import net.orange.architecture.db.Conditions;
import net.orange.architecture.process.ProcessFactory;
import net.orange.framework.logic.IGroupProcess;
import net.orange.framework.model.Group;

/**
 * Group genius is the delegate of IGroupProcess object in system console. it
 * can call the IDepartmentProcess object directly in scripting language
 * directly, but can through the group genius using the "$group" in program.
 */
public class GroupGenius {

	/**
	 * The unique instance of group genius in system.
	 */
	private static GroupGenius instance = null;

	/**
	 * The internal IGroupProcess object
	 */
	private IGroupProcess process;

	/**
	 * Disabled the default constructor, it need to get object instance through
	 * the getInstance method.
	 */
	private GroupGenius() {
		super();
	}

	/**
	 * The private constructor with IGroupProcess object.
	 * 
	 * @param process
	 *            the group process.
	 */
	private GroupGenius(IGroupProcess process) {
		this.process = process;
	}

	/**
	 * Get the unique group genius instance.
	 * 
	 * @return The the department genius instance.
	 * @throws Exception
	 */
	public static GroupGenius getInstance() throws Exception {
		if (instance == null) {
			IGroupProcess _process = (IGroupProcess) ProcessFactory
					.load(Group.class);
			instance = new GroupGenius(_process);
		}
		return instance;
	}

	/**
	 * Retrieve the group according the primary key.
	 * 
	 * @param id
	 *            The group primary key.
	 * @return The target group.
	 * @throws Exception
	 */
	public Group find(long id) throws Exception {
		return (Group) process.find(id);
	}

	/**
	 * Retrieve all the group object.
	 * 
	 * @return The group collection.
	 * @throws Exception
	 */
	public Collection listAll() throws Exception {
		return process.listAll(new Conditions());
	}
}
